package com.example.c_app;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText et_name;

    private EditText ed_id;
    private EditText ed_password;
    private EditText ed_repassword;
    private RadioButton radio_man;
    private RadioButton radio_wuman;
    private Button button_submit;
    private EditText et_emial;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        et_name = (EditText) findViewById(R.id.et_name);

        ed_id = (EditText) findViewById(R.id.ed_id);
        ed_password = (EditText) findViewById(R.id.ed_password);
        ed_repassword = (EditText) findViewById(R.id.ed_repassword);
        radio_man = (RadioButton) findViewById(R.id.radio_man);
        radio_wuman = (RadioButton) findViewById(R.id.radio_wuman);
        button_submit = (Button) findViewById(R.id.button_submit);

        button_submit.setOnClickListener(this);
        et_emial = (EditText) findViewById(R.id.et_emial);
        et_emial.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button_submit:
                submit();
                break;
        }
    }

    private void submit() {
        // validate
        String name = et_name.getText().toString().trim();
        if (TextUtils.isEmpty(name)) {
            Toast.makeText(this, "name不能为空", Toast.LENGTH_SHORT).show();
            return;
        }


        String id = ed_id.getText().toString().trim();


        String password = ed_password.getText().toString().trim();
        if (TextUtils.isEmpty(password)) {
            Toast.makeText(this, "password不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        String repassword = ed_repassword.getText().toString().trim();
        if (TextUtils.isEmpty(repassword)) {
            Toast.makeText(this, "repassword不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        String emial = et_emial.getText().toString().trim();

        String sex="";
        if(radio_man.isChecked()){
            sex=radio_man.getText().toString().trim();
        }else {
            sex=radio_wuman.getText().toString().trim();
        }

        if (!password.equals(repassword)) {
            Toast.makeText(this, "两次密码不一致", Toast.LENGTH_SHORT).show();
            return;
        }

        Intent intent =new Intent(MainActivity.this,Show.class);
        Bundle bundle=new Bundle();
        intent.putExtra("name",name);
        intent.putExtra("id",id);
        intent.putExtra("password",password);
        intent.putExtra("emial",emial);
        intent.putExtra("sex",sex);
        startActivity(intent);


    }


}
